package robotninja.asctec.test.movementcommands;

import java.util.HashMap;

import robotninja.asctec.test.movementcommands.commands.CommandSender;
import robotninja.asctec.test.movementcommands.commands.CommandSender.COMMAND_TYPE;
import robotninja.driver.asctec.AsctecDriver;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

	/**
	 * Asctec Driver.
	 */
	private AsctecDriver driver;
	private CommandSender cs;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// Create the driver
		driver = new AsctecDriver();
		// Try to connect
		try {
			driver.connect(getSerialParameters(this));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return;
		}

		// Turn on motors
		driver.turnOnOff(true);

		// Create the command sender
		cs = new CommandSender(driver);

		// Add the commands
		cs.addCommand(5000, 0, 30, 0, 50);
		cs.addCommand(5000, 0, 0, 30, 50);
		cs.addCommand(5000, 50, 0, 0, 100);

		cs.run();

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	private HashMap<String, Object> getSerialParameters(Activity act) {
		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("Activity", act);
		params.put("baudrate", 57600);
		params.put("dataBits", 8);
		params.put("stopBits", 1);
		params.put("parity", 0);

		return params;
	}
}
